package com.pt25.base.model.security;

import org.slf4j.MDC;

/**
 * 保存用户会话上下文信息（sessionData）
 */
public class SecurityThreadLocal {
    public static final InheritableThreadLocal<UserSession<?>> threadLocal = new InheritableThreadLocal<>();

    public static void set(UserSession<?> userSession) {
        MDC.put("userId", userSession.getUid());
        threadLocal.set(userSession);
    }

    public static void clean() {
        threadLocal.remove();
    }

    public static UserSession<?> get() {
        return threadLocal.get();
    }
}
